package org.hhchat.others.toutiao.p2018;

import java.util.Scanner;
import java.util.Stack;

/**
 * Created this one by huminghao on 2018/3/24.
 */
public class Toutiao01 {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        String exp;

        while (n-- > 0) {
            Stack<Long> stackNumbers = new Stack<>();
            exp = scanner.next();
            exp += ';';
            char op = '#';
            Long lastNumber = 0L;
            for (int i = 0; i < exp.length(); i++) {
                char c = exp.charAt(i);
                if (c == ' ') {
                    continue;
                }
                if (Character.isDigit(c)) {
                    lastNumber = lastNumber * 10 + (c - '0');
                    continue;
                }
                //if (c == ';') {
                //    stackNumbers.add(lastNumber);
                //    lastNumber = 0L;
                //    continue;
                //}
                switch (op) {
                    case '+':
                        stackNumbers.add(lastNumber);
                        lastNumber = 0L;
                        break;
                    case '-':
                        stackNumbers.add(-lastNumber);
                        lastNumber = 0L;
                        break;
                    case '*':
                        lastNumber *= stackNumbers.pop();
                        stackNumbers.add(lastNumber);
                        lastNumber = 0L;
                        break;
                    case '#':
                        stackNumbers.add(lastNumber);
                        lastNumber = 0L;
                        break;
                }
                op = c;

            }
            Long ans = 0L;
            while (!stackNumbers.empty()) {
                ans += stackNumbers.pop();
            }
            System.out.println(ans);
            printResult(ans);
        }

    }

    public static void printResult(Long result) {

        String bits = getBit(result);
        int blockLength = bits.length() * 5 + (bits.length() - 1) * 2;
        char[][] blocks = new char[5][blockLength];
        int last = -7;
        for (int i = 0; i < bits.length(); i++) {
            switch (bits.charAt(i)) {
                case '0':
                    fill(blocks, getZero(), last + 7);
                    break;
                case '1':
                    fill(blocks, getOne(), last + 7);
                    break;
                case '2':
                    fill(blocks, getTwo(), last + 7);
                    break;
                case '3':
                    fill(blocks, getThree(), last + 7);
                    break;
                case '4':
                    fill(blocks, getFour(), last + 7);
                    break;
                case '5':
                    fill(blocks, getFive(), last + 7);
                    break;
                case '6':
                    fill(blocks, getSix(), last + 7);
                    break;
                case '7':
                    fill(blocks, getSeven(), last + 7);
                    break;
                case '8':
                    fill(blocks, getEight(), last + 7);
                    break;
                case '9':
                    fill(blocks, getNine(), last + 7);
                    break;
            }
            if (i != bits.length() - 1) {
                fill(blocks, getSeparet(), last + 12);
            }
            last+=7;
        }
        for(int i = 0; i < blocks.length; i++) {
            for(int j = 0; j < blocks[i].length; j++) {
                System.out.print(blocks[i][j]);
            }
            System.out.println("");
        }
    }

    public static String getBit(Long result) {
        return result.toString();
    }

    public static void fill(char[][] result, String block, int start) {
        String[] lines = block.split("@");
        for (int i = 0; i < lines.length; i++) {
            for (int j = 0; j < lines[0].length(); j++) {
                result[i][start + j] = lines[i].charAt(j);
            }
        }
    }

    public static String getZero() {
        StringBuilder sb = new StringBuilder();
        sb
                .append("66666").append("@")
                .append("6...6").append("@")
                .append("6...6").append("@")
                .append("6...6").append("@")
                .append("66666");
        return sb.toString();
    }

    public static String getSeparet() {
        StringBuilder sb = new StringBuilder();
        sb
                .append("..").append("@")
                .append("..").append("@")
                .append("..").append("@")
                .append("..").append("@")
                .append("..");
        return sb.toString();
    }

    public static String getOne() {
        StringBuilder sb = new StringBuilder();
        sb
                .append("....6").append("@")
                .append("....6").append("@")
                .append("....6").append("@")
                .append("....6").append("@")
                .append("....6");
        return sb.toString();
    }

    public static String getTwo() {
        StringBuilder sb = new StringBuilder();
        sb
                .append("66666").append("@")
                .append("....6").append("@")
                .append("66666").append("@")
                .append("6....").append("@")
                .append("66666");
        return sb.toString();
    }

    public static String getThree() {
        StringBuilder sb = new StringBuilder();
        sb
                .append("66666").append("@")
                .append("....6").append("@")
                .append("66666").append("@")
                .append("....6").append("@")
                .append("66666");
        return sb.toString();
    }

    public static String getFour() {
        StringBuilder sb = new StringBuilder();
        sb
                .append("6...6").append("@")
                .append("6...6").append("@")
                .append("66666").append("@")
                .append("....6").append("@")
                .append("....6");
        return sb.toString();
    }

    public static String getFive() {
        StringBuilder sb = new StringBuilder();
        sb
                .append("66666").append("@")
                .append("6....").append("@")
                .append("66666").append("@")
                .append("....6").append("@")
                .append("66666");
        return sb.toString();
    }

    public static String getSix() {
        StringBuilder sb = new StringBuilder();
        sb
                .append("66666").append("@")
                .append("6....").append("@")
                .append("66666").append("@")
                .append("6...6").append("@")
                .append("66666");
        return sb.toString();
    }

    public static String getSeven() {
        StringBuilder sb = new StringBuilder();
        sb
                .append("66666").append("@")
                .append("....6").append("@")
                .append("....6").append("@")
                .append("....6").append("@")
                .append("....6");
        return sb.toString();
    }

    public static String getEight() {
        StringBuilder sb = new StringBuilder();
        sb
                .append("66666").append("@")
                .append("6...6").append("@")
                .append("66666").append("@")
                .append("6...6").append("@")
                .append("66666");
        return sb.toString();
    }

    public static String getNine() {
        StringBuilder sb = new StringBuilder();
        sb
                .append("66666").append("@")
                .append("6...6").append("@")
                .append("66666").append("@")
                .append("....6").append("@")
                .append("66666");
        return sb.toString();
    }
}
